package com.ruoyi.service.basic.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.basic.MesWorkshop;
import com.ruoyi.mapper.basic.MesWorkshopMapper;
import com.ruoyi.service.basic.IMesWorkshopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 车间信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@Service
public class MesWorkshopServiceImpl implements IMesWorkshopService {
    @Autowired
    private MesWorkshopMapper mesWorkshopMapper;

    /**
     * 查询车间信息
     * 
     * @param workshopId 车间信息主键
     * @return 车间信息
     */
    @Override
    public MesWorkshop selectMesWorkshopByWorkshopId(Long workshopId) {
        return mesWorkshopMapper.selectMesWorkshopByWorkshopId(workshopId);
    }

    /**
     * 查询车间信息列表
     * 
     * @param mesWorkshop 车间信息
     * @return 车间信息
     */
    @Override
    public List<MesWorkshop> selectMesWorkshopList(MesWorkshop mesWorkshop) {
        return mesWorkshopMapper.selectMesWorkshopList(mesWorkshop);
    }

    /**
     * 新增车间信息
     * 
     * @param mesWorkshop 车间信息
     * @return 结果
     */
    @Override
    public int insertMesWorkshop(MesWorkshop mesWorkshop) {
        mesWorkshop.setCreateTime(DateUtils.getNowDate());
        return mesWorkshopMapper.insertMesWorkshop(mesWorkshop);
    }

    /**
     * 修改车间信息
     * 
     * @param mesWorkshop 车间信息
     * @return 结果
     */
    @Override
    public int updateMesWorkshop(MesWorkshop mesWorkshop) {
        mesWorkshop.setUpdateTime(DateUtils.getNowDate());
        return mesWorkshopMapper.updateMesWorkshop(mesWorkshop);
    }

    /**
     * 批量删除车间信息
     * 
     * @param workshopIds 需要删除的车间信息主键
     * @return 结果
     */
    @Override
    public int deleteMesWorkshopByWorkshopIds(Long[] workshopIds) {
        return mesWorkshopMapper.deleteMesWorkshopByWorkshopIds(workshopIds);
    }

    /**
     * 删除车间信息
     * 
     * @param workshopId 车间信息主键
     * @return 结果
     */
    @Override
    public int deleteMesWorkshopByWorkshopId(Long workshopId) {
        return mesWorkshopMapper.deleteMesWorkshopByWorkshopId(workshopId);
    }

    /**
     * 校验车间编码是否唯一
     * 
     * @param mesWorkshop 车间信息
     * @return 结果
     */
    @Override
    public String checkWorkshopCodeUnique(MesWorkshop mesWorkshop) {
        Long workshopId = StringUtils.isNull(mesWorkshop.getWorkshopId()) ? -1L : mesWorkshop.getWorkshopId();
        MesWorkshop info = mesWorkshopMapper.checkWorkshopCodeUnique(mesWorkshop.getWorkshopCode());
        if (StringUtils.isNotNull(info) && info.getWorkshopId().longValue() != workshopId.longValue()) {
            return "1"; // 不唯一
        }
        return "0"; // 唯一
    }

    /**
     * 查询启用状态的车间列表
     * 
     * @return 车间列表
     */
    @Override
    public List<MesWorkshop> selectActiveWorkshopList() {
        return mesWorkshopMapper.selectActiveWorkshopList();
    }
}